import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  server: {
    host: '0.0.0.0',
    port: 5173,
    open: false,
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => {
          console.log('path', path)
          return path.replace(/^\/api/, '')
        },
        configure: (proxy, options) => {
            // 配置此项可在响应头中看到请求的真实地址
            proxy.on('proxyRes', (proxyRes, req) => {
                proxyRes.headers['x-real-url'] = new URL(req.url || '', options.target)?.href || ''
            })
        },
      }
    }
  },
  resolve: {
    alias: {
      '@': '/src',
    },
  },
})
